#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

bool prostch(int ch) {
    if (ch <= 1) return false;
    for (int i = 2; i * i <= ch; i++) {
        if (ch % i == 0) return false;
    }
    return true;
}

int slovovch (const string& slovo1, const string& slovo2, const string& slovo3) {
    vector<string> slovSlov = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    int ch1 = find(slovSlov.begin(), slovSlov.end(), slovo1) - slovSlov.begin();
    int ch2 = find(slovSlov.begin(), slovSlov.end(), slovo2) - slovSlov.begin();
    int ch3 = find(slovSlov.begin(), slovSlov.end(), slovo3) - slovSlov.begin();
return ch1 * 100 + ch2 * 10 + ch3;
}
int main() {
    string slova, slovo1, slovo2, slovo3; 
    getline(cin, slova);
    istringstream s(slova);
    s >> slovo1 >> slovo2 >> slovo3;
    
    if (slovo1 == "zero" || slovo2 == "zero" || slovo3 == "zero") { 
        cout << "Wrong input" << endl;
        return 1;
    }
    int ch = slovovch (slovo1, slovo2, slovo3);
    if (ch < 100 || ch > 999) {
        cout << "Wrong input" << endl;
        return 1;
    }
    int mensh = ch, bolsh = ch;
    while (true) {
        if (prostch(mensh)) {
            cout << mensh << endl;
            return 0;
        }
        if (prostch(bolsh)) {
            cout << bolsh << endl;
            return 0;
        }
        mensh--;
        bolsh++;
    }
return 0;
}